﻿using System;
using System.Windows.Forms;

namespace 物流管理系统
{
    public partial class Membertypeinfo : Form
    {
        DBOperation dboperation = new DBOperation();
        string sqlstr;
        public int formtype;
        ReMatch re = new ReMatch();
        public Membertypeinfo()
        {
            InitializeComponent();
        }

        private void confirm_Click(object sender, EventArgs e)
        {
            foreach (Control c in Controls)
            {
                if (c is TextBox txt)
                {
                    if (txt.Text==""&&(!c.Name.Equals("remarkstext")))
                    {
                        MessageBox.Show("有重要项目为空，请检查！！！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }
            }
            if (!re.chcharmatch(idtext.Text))
            {
                MessageBox.Show("会员类型名输入非法！！！\n格式位纯中文的字符串。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if ((!(re.decmatch(discounttext.Text)||re.intmatch(discounttext.Text)))||discounttext.TextLength>3)
            {
                MessageBox.Show("折扣输入非法！！！\n格式为1位10以内整数或1位小数。", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            switch (formtype)
            {
                case 0://添加
                    {
                        if (dboperation.exists("select "+idlabel.Text+" from "+Text+"表 where "+idlabel.Text+"='"+idtext.Text+"'", idtext.Text))
                        {
                            MessageBox.Show("此会员类型已经存在！！！", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            return;
                        }
                        else
                        {
                            sqlstr="insert into 会员类型信息表 VALUES('"+idtext.Text+"','"+discounttext.Text+"');";
                        }
                        break;
                    }
                case 1://修改
                    {
                        sqlstr="replace into 会员类型信息表 VALUES('"+idtext.Text+"','"+discounttext.Text+"');";
                        break;
                    }
                case 2://查看
                    {
                        Close();
                        break;
                    }
            }
            dboperation.nonquerysql(sqlstr);
            Close();
        }

        private void Membertypeinfo_Load(object sender, EventArgs e)
        {
            switch (formtype)
            {
                case 0://添加
                    {
                        break;
                    }
                case 1://修改
                    {
                        idtext.Enabled=false;
                        break;
                    }
                case 2://查看
                    {
                        foreach (Control c in Controls)
                        {
                            if (!(c is Button))
                            {
                                c.Enabled=false;
                            }
                        }
                        break;
                    }
            }
        }
    }
}
